insert overwrite table jms_dm.dm_mng_thd_flase_send_network_summary_dt partition (dt)
select date_time
     , first_duty_network_code
     , first_duty_network_name
     , first_duty_network_type
     , first_duty_agent_code
     , first_duty_agent_name
     , sum(if(first_duty_type in (1, 2, 3, 4), 1, 0))         as all_num
     , sum(if(first_duty_type = 1, 1, 0))                     as first_line_num
     , sum(if(first_duty_type = 2, 1, 0))                     as outprov_center_num
     , sum(if(first_duty_type = 3, 1, 0))                     as same_center_num
     , sum(if(first_duty_type = 4, 1, 0))                     as adjacent_track
     , from_unixtime(unix_timestamp(), 'yyyy-MM-dd HH:mm:ss') as update_time
     , dt
from jms_dm.dm_mng_thd_flase_send_waybill_detail_dt
where dt >= date_add('{{ execution_date | cst_ds }}', -30)
  and dt <= '{{ execution_date | cst_ds }}'
  and first_duty_type in (1, 2, 3, 4)
group by date_time
       , first_duty_network_code
       , first_duty_network_name
       , first_duty_network_type
       , first_duty_agent_code
       , first_duty_agent_name
       , dt
    distribute by dt
;